package com.css.zfzx.fwsjcj.modules.structure.repository;

import com.css.zfzx.fwsjcj.commen.util.Constant;
import com.css.zfzx.fwsjcj.modules.structure.entity.FwOtherStructureEntity;
import com.css.zfzx.fwsjcj.modules.structure.vo.TestVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author leon
 * @Title: FwBrickStructureRepository
 * @Description: 砖混结构
 * @date 2020/6/3 10:05
 */
@Repository
public interface FwOtherStructureRepository extends JpaRepository<FwOtherStructureEntity, String>,
        QuerydslPredicateExecutor<FwOtherStructureEntity>, JpaSpecificationExecutor<FwOtherStructureEntity> {
    FwOtherStructureEntity findByOtherStructureNumAndDelFlag(String otherStructureNum, String isValid);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_other_structure set detail_file =:fileId where id =:formId")
    void update(@Param("formId") String formId, @Param("fileId") String fileId);

    /**
     * 多表关联查询（JPQL方式）
     */
    @Query(value = "select new com.css.zfzx.fwsjcj.modules.structure.vo.TestVo(s.structureType, b.buildingName) from " +
            "FwOtherStructureEntity b, FwStructureFormEntity s where s.structureId = b.id")
    List<TestVo> listTestVo();

    /**
     * 查询在idList中数据
     */
    //@Query(nativeQuery = true, value = "select * from fw_other_structure where del_flag =" + Constant.DEL_NO + " and id in :idList")
    @Query(nativeQuery = true, value = "select * from fw_other_structure where id in :idList")
    List<FwOtherStructureEntity> findInIdList(@Param("idList") List<String> idList);
}
